(function() {
    angular.module('app').factory('chartLineService', chartLineService);

    chartLineService.$inject = ['$q', 'util'];

    function chartLineService($q, util) {
        return {
            get: get
        }

        function get(catName, options) {
            var defer = $q.defer();
            options.xAxis.data.length = 0;
            options.series[0].data.length = 0; //总和
            options.series[1].data.length = 0; //天猫
            options.series[2].data.length = 0; //淘宝
            options.series[3].data.length = 0; //天猫国际
            options.series[4].data.length = 0; //全球购

            util.$get({
                url: '/marketconditions/statistic/getCategoryStatisticIndex.htm',
                data: {
                    catName: catName
                }
            }).then(function(resp) {
                if (resp.value.length > 0) { //有数据
                    angular.forEach(resp.value, function(item, index) {

                        options.xAxis.data.push(item.date.split(' ')[0]);
                        options.series[0].data.push(item.sellMoney);
                        options.series[1].data.push(item.tSellMoney);
                        options.series[2].data.push(item.cSellMoney);
                        options.series[3].data.push(item.thkSellMoney);
                        options.series[4].data.push(item.gSellMoney);
                    });

                } else { //没有数据

                }


                defer.resolve();
            }, function(err) {
                defer.reject();
            });

            return defer.promise;
        }
    }
})();
